package com.kalix.training.hotlists.biz;

import com.kalix.framework.core.api.persistence.JsonData;
import com.kalix.framework.core.impl.biz.ShiroGenericBizServiceImpl;
import com.kalix.training.hotlists.api.biz.ISelectedCourseBeanService;
import com.kalix.training.hotlists.api.dao.ISelectedCourseBeanDao;
import com.kalix.training.hotlists.api.dto.SelectedCourseDTO;
import com.kalix.training.hotlists.entities.SelectedCourseBean;

import java.util.List;

public class SelectedCourseBeanServiceImpl extends ShiroGenericBizServiceImpl<ISelectedCourseBeanDao, SelectedCourseBean>
implements ISelectedCourseBeanService {

    /**
     * 精选课程（关联表：课程表，用户表，课程类别表，院系类别表）
     * @param page,limit,jsonStr,sort
     * @return jsondata
     */
    @Override
    public JsonData getAllSelectedCourse() {
        String sql = "select s.id,s.identify,s.cid,c.name as cname,c.photo,c.introduction,c.classhour,c.credit,c.points,ct.name as gname,d.content as dname,u.name AS uname\n" +
                "from mooc_selectedcourse s,mooc_course c,sys_user u,mooc_coursecategory ct,mooc_departments d\n" +
                "where s.cid = c.id and c.uid = u.id and c.gid = ct.id and c.did = d.id ORDER BY s.identify";
        List<SelectedCourseDTO> list = dao.findByNativeSql(sql, SelectedCourseDTO.class);
        JsonData jsonData = new JsonData();
        jsonData.setData(list);
        jsonData.setTotalCount((long) list.size());
        return jsonData;
    }
}
